﻿
using UnityEngine;

public class DataHandle
{
    public static DataHandle Instance;
    public void OnRegist()
    {
        Facade.Instance.RegistNetEvent(nameof(notify_kick), OnNotifyKickRsp);
        Facade.Instance.RegistNetEvent(nameof(notify_error), OnNotifyErrorRsp);
        Facade.Instance.RegistNetEvent(nameof(notify_enterroom), OnNotifyEnterroom);
    }

    public void OnUnRegist()
    {
        Facade.Instance.UnRegistNetEvent(nameof(notify_kick), OnNotifyKickRsp);
        Facade.Instance.UnRegistNetEvent(nameof(notify_error), OnNotifyErrorRsp);
        Facade.Instance.UnRegistNetEvent(nameof(notify_enterroom), OnNotifyEnterroom);
    }

    private void OnNotifyKickRsp(System.Object data)
    {
        var rsp = data as notify_kick;
        UITips.Instance.Show("你被踢下线:" + rsp.msg);
    }

    private void OnNotifyErrorRsp(System.Object data)
    {
        var rsp = data as notify_error;
        UITips.Instance.Show("notify_error:" + rsp.reason + " code:" + rsp.ret);
    }

  
    public DataBattleMgr dataBattleMgr;
    private void OnNotifyEnterroom(System.Object data)  //预防场景没初始化完，收到消息
    {
        if (dataBattleMgr == null)
            return;

        var rsp = data as notify_enterroom;
        if (dataBattleMgr.GetDataPlayer(rsp.member.uid) == null)
        {
            dataBattleMgr.AddDataPlayer(rsp.member);
        }

    }
}

